<template>
  <view class="content">
<!--    <image class="logo" src="@/static/logo.png"></image>
    <view class="text-area">
      <text class="title">Hello RuoYi</text>
    </view> -->
	<!-- 轮播图 -->
	<uni-swiper-dot class="uni-swiper-dot-box" :info="data" :current="current" field="content">
	  <swiper class="swiper-box" :current="swiperDotIndex" @change="changeSwiper">
	    <swiper-item v-for="(item, index) in data" :key="index">
	      <view class="swiper-item" @click="clickBannerItem(item)">
	        <image :src="item.pic" mode="aspectFill" :draggable="false" />
	      </view>
	    </swiper-item>
	  </swiper>
	</uni-swiper-dot>


    <!-- 宫格组件 -->
    <uni-section title="反诈宣传栏" type="line"></uni-section>
    <view class="grid-body">
      <uni-grid :column="4" :showBorder="false" @change="changeGrid">
        <uni-grid-item v-if=false>
          <view class="grid-item-box" @click="toQyMap">
            <uni-icons type="location" size="30"></uni-icons>
			<!-- 字体图标的使用，1.在static中加入css文件，在index.vue中引入样式，如下使用 -->
			<!-- <view class="iconfont icon-diannao"></view> -->
            <text class="text">全域地图</text>
          </view>
        </uni-grid-item>
<!--        <uni-grid-item>
          <view class="grid-item-box" @click="toBadiduMap">
            <uni-icons type="location" size="30"></uni-icons>
            <text class="text">反诈宣传点</text>
          </view>
        </uni-grid-item> -->
		<uni-grid-item>
		  <view class="grid-item-box" @click="toBadiduMapEx">
		    <uni-icons type="location" size="30"></uni-icons>
		    <text class="text">反诈宣传点</text>
		  </view>
		</uni-grid-item>
        <uni-grid-item v-if=false>
          <view class="grid-item-box" @click="toScenic">
            <uni-icons type="color" size="30"></uni-icons>
            <text class="text">景点一览</text>
          </view>
        </uni-grid-item>
        <uni-grid-item v-if=false>
          <view class="grid-item-box" @click="toHotel">
            <uni-icons type="settings-filled" size="30"></uni-icons>
            <text class="text">酒店推荐</text>
          </view>
        </uni-grid-item>
<!--        <uni-grid-item>
          <view class="grid-item-box" @click="toShop">
            <uni-icons type="star" size="30"></uni-icons>
            <text class="text">反诈推广</text>
          </view>
        </uni-grid-item> -->
		<uni-grid-item>
		  <view class="grid-item-box" @click="toFzxc">
		    <uni-icons type="star" size="30"></uni-icons>
		    <text class="text">反诈推广</text>
		  </view>
		</uni-grid-item>
        <uni-grid-item>
          <view class="grid-item-box" @click="toVedio">
            <uni-icons type="videocam" size="30"></uni-icons>
            <text class="text">反诈视频</text>
          </view>
        </uni-grid-item>
        <uni-grid-item v-if="false">
          <view class="grid-item-box">
            <uni-icons type="gear-filled" size="30"></uni-icons>
            <text class="text">活动通知</text>
          </view>
        </uni-grid-item>
<!--        <uni-grid-item>
          <view class="grid-item-box" @click="toTravel">
            <uni-icons type="chat" size="30"></uni-icons>
            <text class="text">案例警示</text>
          </view>
        </uni-grid-item> -->
		<uni-grid-item>
		  <view class="grid-item-box" @click="toFzal">
		    <uni-icons type="chat" size="30"></uni-icons>
		    <text class="text">案例警示</text>
		  </view>
		</uni-grid-item>
		<uni-grid-item>
		  <view class="grid-item-box" @click="toHmSearch">
		    <uni-icons type="search" size="30"></uni-icons>
		    <text class="text">号码查询</text>
		  </view>
		</uni-grid-item>
		<uni-grid-item>
		  <view class="grid-item-box" @click="toAI">
		    <uni-icons type="chatbubble" size="30"></uni-icons>
		    <text class="text">AI反诈</text>
		  </view>
		</uni-grid-item>
      </uni-grid>
    </view>
	<!-- 推荐内容组件 -->
	<uni-section title="为你推荐" type="line"></uni-section>
	<!-- <image :src="url" mode="aspectFill" :draggable="false" /> -->
	<view class="wrap">
			<!-- <u-button @click="clear">清空列表</u-button> -->
			<u-waterfall v-model="flowList" ref="uWaterfall">
				<template v-slot:left="{leftList}">
					<view class="demo-warter" v-for="(item, index) in leftList" :key="index" @click="toWebView(item)">
<!-- <uni-link href="https://uniapp.dcloud.io/" text="https://uniapp.dcloud.io/"></uni-link> -->

						<!-- 警告：微信小程序中需要hx2.8.11版本才支持在template中结合其他组件，比如下方的lazy-load组件 -->
						<u-lazy-load threshold="-450" border-radius="10" :image="item.images" :index="index"></u-lazy-load>
						<view class="demo-title">
							{{item.title}}
						</view>
<!-- 						<view class="demo-price">
							{{item.price}}元
						</view>
						<view class="demo-tag">
							<view class="demo-tag-owner">
								自营
							</view>
							<view class="demo-tag-text">
								放心购
							</view>
						</view> -->
						<view v-if="false" class="demo-shop">
							{{item.shop}}
						</view>
						<!-- <u-icon name="close-circle-fill" color="#fa3534" size="34" class="u-close" @click="remove(item.id)"></u-icon> -->
					</view>
				</template>
				<template v-slot:right="{rightList}">
					<view class="demo-warter" v-for="(item, index) in rightList" :key="index" @click="toWebView(item)">
						<u-lazy-load threshold="-450" border-radius="10" :image="item.images" :index="index"></u-lazy-load>
						<view class="demo-title">
							{{item.title}}
						</view>
<!-- 						<view class="demo-price">
							{{item.price}}元
						</view>
						<view class="demo-tag">
							<view class="demo-tag-owner">
								自营
							</view>
							<view class="demo-tag-text">
								放心购
							</view>
						</view> -->
						<view v-if="false" class="demo-shop">
							{{item.shop}}
						</view>
						<!-- <u-icon name="close-circle-fill" color="#fa3534" size="34" class="u-close" @click="remove(item.id)"></u-icon> -->
					</view>
				</template>
			</u-waterfall>
			<u-loadmore bg-color="rgb(240, 240, 240)" :status="loadStatus" @loadmore="addRandomData"></u-loadmore>
		</view>
	
  </view>
</template>

<script>
  import config from '@/config'
  import { getArticle,getCarousel } from "@/api/article/article.js"
	
  export default {
	  data() {
	    return {
		  url:null,
	      current: 0,
	      swiperDotIndex: 0,
	      data: [{
	          image: '/static/images/banner/banner01.jpg'
	        },
	        {
	          image: '/static/images/banner/banner02.jpg'
	        },
	        {
	          image: '/static/images/banner/banner03.jpg'
	        }
	      ],
		  loadStatus: 'loadmore',
		  //为你推荐数据
			flowList: [],
			list: [

				{
					price: 784,
					title: '欲与天公试比高',
					shop: '李白杜甫白居易旗舰店',
					image: 'http://pic2.sc.chinaz.com/Files/pic/pic9/202002/zzpic23369_s.jpg',
				},
				{
					price: 7891,
					title: '须晴日，看红装素裹，分外妖娆',
					shop: '李白杜甫白居易旗舰店',
					image: 'http://pic2.sc.chinaz.com/Files/pic/pic9/202002/hpic2130_s.jpg',
				},
				{
					price: 2341,
					shop: '李白杜甫白居易旗舰店',
					title: '江山如此多娇，引无数英雄竞折腰',
					image: 'http://pic1.sc.chinaz.com/Files/pic/pic9/202002/zzpic23346_s.jpg',
				},
				{
					price: 8243,
					title: '俱往矣，数风流人物，还看今朝',
					shop: '李白杜甫白居易旗舰店',
					image: 'http://pic1.sc.chinaz.com/Files/pic/pic9/202002/zzpic23343_s.jpg',
				},
			]
	    }
	  },
	  methods: {
	    clickBannerItem(item) {
	      console.info(item)
	    },
	    changeSwiper(e) {
	      this.current = e.detail.current
	    },
		addRandomData() {
			// console.log("aaa")
			for(let i = 0; i < 10; i++) {
					let index = this.$u.random(0, this.list.length - 1);
					// 先转成字符串再转成对象，避免数组对象引用导致数据混乱
					let item = JSON.parse(JSON.stringify(this.list[index]))
					item.id = this.$u.guid();
					this.flowList.push(item);
				}
			},
			remove(id) {
				this.$refs.uWaterfall.remove(id);
			},
			clear() {
				this.$refs.uWaterfall.clear();
			},
			//为你推荐数据获取
			getRecommendArticle()
			{
				let data={pageNum:1,pageSize:10};
				getArticle(data).then(response => {
					// console.log(response);
					this.list=response.rows
					this.addRandomData();
				})
				
			},
			//获取首页轮播
			getSYCarousel()
			{
				getCarousel().then(response => {
					// console.log(response);
					// this.data=response.data.carouselItemList
					let temp=response.data.carouselItemList
					// 使用for...of循环遍历对象数组
					for (let obj of temp) {
					    obj.pic=config.minioUrl+'/'+obj.pic;
					}
					this.data=temp;
				})
				
			},
			changeGrid(e) {
			  // this.$modal.showToast('模块建设中~')
			},
			
			toQyMap(e) {
			  this.$tab.navigateTo('/pages/map/index')
			},
			toBadiduMap(e) {
			  this.$tab.navigateTo('/pages/maptx/index')
			},
			toBadiduMapEx(e) {
			  // console.log(url.staticUrl);
			  // url.staticUrl="www.baidu.com"
			  var url = "http://122.152.207.166/tx-map.html";
			  // this.$tab.navigateTo(`/pages/common/webview/index?title="aaa"&url=${url.staticUrl}`)
			   	uni.navigateTo({
			   		// 此处的链接为小程序上面新建的webview页面路径，参数url为要跳转外链的地址
			   		url: "/pages/webview/index?url=" + encodeURIComponent(url)+'&title='+"地图"
			   	});
			},
			toScenic(e) {
			  this.$tab.navigateTo('/pages/scenic/index')
			},
			toVedio(e) {
			  this.$tab.navigateTo('/pages/vedio/index')
			},
			toHotel(e) {
			  this.$tab.navigateTo('/pages/hotel/index')
			},
			toShop(e) {
			  this.$tab.navigateTo('/pages/shop/index')
			},
			toFzxc(e) {
			  this.$tab.navigateTo('/pages/fzxc/index')
			},
			toTravel(e) {
			  this.$tab.navigateTo('/pages/travelguides/index')
			},
			toFzal(e) {
			  this.$tab.navigateTo('/pages/fzxc/anli')
			},
			toHmSearch(e) {
			  this.$tab.navigateTo('/pages/hmsearch/index')
			},
			toAI(e) {
			  this.$tab.navigateTo('/pages/ai/index')
			},
			toWebView(url) {
			  // console.log(url.staticUrl);
			  // url.staticUrl="www.baidu.com"
			  var url = url;
			  // this.$tab.navigateTo(`/pages/common/webview/index?title="aaa"&url=${url.staticUrl}`)
			   	uni.navigateTo({
			   		// 此处的链接为小程序上面新建的webview页面路径，参数url为要跳转外链的地址
			   		url: "/pages/webview/index?url=" + encodeURIComponent(url.staticUrl)+'&title='+"标题"
			   	});
			}
	  },
    onLoad: function() {
		this.url=config.minioUrl+'/npdxpcwl/Carousel/2024/02/19/425586dc.jpg';
		// this.addRandomData();
		//获取首页为你推荐功能
		this.getRecommendArticle()
		//获取首页轮播
		this.getSYCarousel()
		
    },
	onReachBottom() {
				this.loadStatus = 'loading';
				// 模拟数据加载
				setTimeout(() => {
					this.addRandomData();
					this.loadStatus = 'loadmore';
				}, 1000)
			}
  }
</script>

<style lang="scss">
  /* #ifndef APP-NVUE */
  page {
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    background-color: #fff;
    min-height: 100%;
    height: auto;
  }

  view {
    font-size: 14px;
    line-height: inherit;
  }

  /* #endif */

  .text {
    text-align: center;
    font-size: 26rpx;
    margin-top: 10rpx;
  }

  .grid-item-box {
    flex: 1;
    /* #ifndef APP-NVUE */
    display: flex;
    /* #endif */
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 15px 0;
  }

  .uni-margin-wrap {
    width: 690rpx;
    width: 100%;
    ;
  }

  .swiper {
    height: 300rpx;
  }

  .swiper-box {
    height: 150px;
  }

  .swiper-item {
    /* #ifndef APP-NVUE */
    display: flex;
    /* #endif */
    flex-direction: column;
    justify-content: center;
    align-items: center;
    color: #fff;
    height: 300rpx;
    line-height: 300rpx;
  }

  @media screen and (min-width: 500px) {
    .uni-swiper-dot-box {
      width: 400px;
      /* #ifndef APP-NVUE */
      margin: 0 auto;
      /* #endif */
      margin-top: 8px;
    }

    .image {
      width: 100%;
    }
  }
  
  .demo-warter {
  		border-radius: 8px;
  		margin: 5px;
  		background-color: #ffffff;
  		padding: 8px;
  		position: relative;
  	}
  	
  	.u-close {
  		position: absolute;
  		top: 32rpx;
  		right: 32rpx;
  	}
  	
  	.demo-image {
  		width: 100%;
  		border-radius: 4px;
  	}
  	
  	.demo-title {
  		font-size: 30rpx;
  		margin-top: 5px;
  		color: $u-main-color;
  	}
  	
  	.demo-tag {
  		display: flex;
  		margin-top: 5px;
  	}
  	
  	.demo-tag-owner {
  		background-color: $u-type-error;
  		color: #FFFFFF;
  		display: flex;
  		align-items: center;
  		padding: 4rpx 14rpx;
  		border-radius: 50rpx;
  		font-size: 20rpx;
  		line-height: 1;
  	}
  	
  	.demo-tag-text {
  		border: 1px solid $u-type-primary;
  		color: $u-type-primary;
  		margin-left: 10px;
  		border-radius: 50rpx;
  		line-height: 1;
  		padding: 4rpx 14rpx;
  		display: flex;
  		align-items: center;
  		border-radius: 50rpx;
  		font-size: 20rpx;
  	}
  	
  	.demo-price {
  		font-size: 30rpx;
  		color: $u-type-error;
  		margin-top: 5px;
  	}
  	
  	.demo-shop {
  		font-size: 22rpx;
  		color: $u-tips-color;
  		margin-top: 5px;
  	}
</style>
